package com.titan.single.vo;


import com.titan.single.constant.ResultCode;

import java.io.Serializable;

public class Result<T> implements Serializable{

	private static final long serialVersionUID = 1L;

	/**
	 * 响应状态码
	 */
	private Integer status;
	/**
	 * 消息描述
	 */
	private String message;
	/**
	 * 返回的数据
	 */
	private T data;

	/**
	 * 操作描述
	 */
	private transient String desc;

	public Result() {
		super();
	}

	/**
	 * @param status
	 * @param message
	 */
	public Result(Integer status, String message) {
		super();
		this.status = status;
		this.message = message;
	}

	/**
	 * @param status
	 * @param message
	 * @param data
	 */
	public Result(Integer status, String message, T data) {
		super();
		this.status = status;
		this.message = message;
		this.data = data;
	}

	public Result(Integer status, String message, T data, String desc) {
		this.status = status;
		this.message = message;
		this.data = data;
		this.desc = desc;
	}

	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	@Override
	public String toString() {
		return "Result [status=" + status + ", message=" + message + ", data=" + data + "]";
	}

	//成功返回带数据
	public static <T> Result<T> returnSuccess(T data){
		Result<T> result = new Result<>();
		result.setStatus(ResultCode.CODE_0);
		result.setData(data);
		return result;
	}

	//成功返回带消息
	public static Result returnSuccessWithMsg(String msg){
		Result result = new Result();
		result.setStatus(ResultCode.CODE_0);
		result.setMessage(msg);
		return result;
	}
	//成功返回带消息
	public static Result returnSuccessWithMsg(String msg,String desc){
		Result result = new Result();
		result.setStatus(ResultCode.CODE_0);
		result.setMessage(msg);
		result.setDesc(desc);
		return result;
	}

	//成功返回带消息 + 数据
	public static <T> Result<T> returnSuccessWithMsgAndData(T data,String msg){
		Result<T> result = new Result<>();
		result.setStatus(ResultCode.CODE_0);
		result.setMessage(msg);
		result.setData(data);
		return result;
	}

	//失败返回带消息
	public static Result returnFail(String msg){
		Result result = new Result<>();
		result.setStatus(ResultCode.CODE_1);
		result.setMessage(msg);
		return result;
	}
	//失败返回带消息
	public static Result returnFail(String msg,String desc){
		Result result = new Result<>();
		result.setStatus(ResultCode.CODE_1);
		result.setMessage(msg);
		result.setDesc(desc);
		return result;
	}
}
